/**
 * 作者：陈文斌 on 2019/1/11.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/ClientManager/client_info_model.dart';
import 'package:crm/model/main_scoped_model.dart';
import 'package:crm/view/Tile/list_tile_text_field.dart';
import 'package:crm/view/Tile/list_tile_text.dart';
import 'package:crm/page/IndustryCategory/industry_category_page.dart';

class ClientInfoEditSection extends StatefulWidget {
  final ClientInfoModel client;

  @override
  ClientInfoEditSection({
    Key key,
    @required this.client,
  }) : super(key: key);

  State<StatefulWidget> createState() => _ClientInfoEditSectionState();
}

class _ClientInfoEditSectionState extends State<ClientInfoEditSection> {
  final TextStyle _titleStyle = TextStyle(
    color: AppColors.DetailTextColor,
    fontSize: AppFontSizes.Font15,
    fontFamily: AppFontFamilies.PingFangSC,
    fontWeight: FontWeight.w500,
  );

  ClientInfoModel _client;

  FocusNode _companyNameFocusNode = FocusNode();
  FocusNode _companyPhoneFocusNode = FocusNode();
  FocusNode _companyLocationFocusNode = FocusNode();
  FocusNode _companyStreetAddressFocusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    _client = widget.client ?? ClientInfoModel.fromJson({});
    return Column(
      children: <Widget>[
        ListTileTextField(
          requiredVisible: false,
          dividerVisible: true,
          title: Text(
            '公司名称',
            style: _titleStyle,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          content: _client.companyName ?? '',
          focusNode: _companyNameFocusNode,
          textInputAction: TextInputAction.next,
          onEditingComplete: () =>
              FocusScope.of(context).requestFocus(_companyPhoneFocusNode),
          onChanged: (companyName) {
            _client.companyName = companyName;
          },
        ),
        Padding(padding: EdgeInsets.only(top: 5)),
        ListTileText(
          title: Text(
            '行业类别',
            style: _titleStyle,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          content: _client.industryClassification ?? '',
          onTap: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => IndustryCategoriesPage(),
              ),
            );
          },
        ),
        ListTileTextField(
          title: Text(
            '公司电话',
            style: _titleStyle,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          content: _client.phone ?? '',
          focusNode: _companyPhoneFocusNode,
          textInputAction: TextInputAction.next,
          onEditingComplete: () =>
              FocusScope.of(context).requestFocus(_companyLocationFocusNode),
          onChanged: (phone) {
            _client.phone = phone;
          },
        ),
        ListTileTextField(
          title: Text(
            '公司地址',
            style: _titleStyle,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          content: _client.location ?? '',
          focusNode: _companyLocationFocusNode,
          textInputAction: TextInputAction.next,
          onEditingComplete: () => FocusScope.of(context)
              .requestFocus(_companyStreetAddressFocusNode),
          onChanged: (location) {
            _client.location = location;
          },
        ),
        ListTileTextField(
          title: Text(
            '公司街道地址',
            style: _titleStyle,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          content: _client.streetaddress ?? '',
          focusNode: _companyStreetAddressFocusNode,
          onEditingComplete: () =>
              FocusScope.of(context).requestFocus(FocusNode()),
          onChanged: (streetAddress) {
            _client.streetaddress = streetAddress;
          },
        ),
      ],
    );
  }
}
